package jenry.handlertest;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;

public class Gan_HandlerTest2 extends Activity {
    /** Called when the activity is first created. */
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        System.out.println("Activity-->" + Thread.currentThread().getId());
		HandlerThread handlerThread = new HandlerThread("handler_thread"){};
        handlerThread.start();
        
        MyHandler myHandler = new MyHandler(handlerThread.getLooper());
        Message msg = myHandler.obtainMessage();
        
        Bundle b = new Bundle();
        b.putInt("age",20);
        b.putString("name","school");
        msg.setData(b);
        msg.sendToTarget();
    }
    
    class MyHandler extends Handler{
    	public MyHandler(){
    		
    	}
    	
    	public MyHandler(Looper looper){
    		super(looper);
    	}
    	
		@Override
		public void handleMessage(Message msg) {
			Bundle b = msg.getData();
			int age = b.getInt("age");
			String name = b.getString("name");
			System.out.println("age is " + age + ", name is "+name);
			System.out.println("Handler-->" + Thread.currentThread().getId());
			System.out.println("handlerMessage");
			
		}
    	
    }
   
}